/******************************************************************************
 *  _____     _____
 *  \  __\    \  __\
 *   \ \_\\    \ \_\\
 *    \  __\SS  \  __\roject
 *     \_\       \_\
 *
 * Mateusz Maciąg, Rafał Urbański
 * Komputerowe Systemy Sterowania
 *****************************************************************************/

#include "InputRandomDesigner.h"
#include "ui_InputRandomDesigner.h"

#include <QMessageBox>

using namespace std;

InputRandomDesigner::InputRandomDesigner(QWidget *parent) :
    InputDesigner(parent),
    ui(new Ui::InputRandomDesigner)
{
    ui->setupUi(this);
}

InputRandomDesigner::~InputRandomDesigner()
{
    delete ui;
}

void InputRandomDesigner::attachInput(RafMat::SimInterface::IConfigurableSPtr ctrl)
{
    m_inputConf = ctrl;

    try
    {
        string variance = m_inputConf->getParameter("variance");
        string offset = m_inputConf->getParameter("offset");

        ui->cfgVariance->setValue(QString::fromStdString(variance).toDouble());
        ui->cfgOffset->setValue(QString::fromStdString(offset).toDouble());
    }
    catch(std::logic_error &e)
    {
        QMessageBox::warning(this, "Error", e.what());
    }
}

void InputRandomDesigner::applySettings()
{
    try
    {
        string variance = ui->cfgVariance->text().toStdString();
        string offset = ui->cfgOffset->text().toStdString();

        m_inputConf->setParameter("variance", variance);
        m_inputConf->setParameter("offset", offset);
    }
    catch(std::logic_error &e)
    {
        QMessageBox::warning(this, "Error", e.what());
    }
}
